<!--
* description: 箱号打印数量
-->
<template>
  <section class="editCarBrand">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      title="箱号打印数量"
      :append-to-body="true"
      :visible.sync="showDialog"
      width="400px"
      @close="close"
    >
      <dialogHeader slot="title" title="箱号打印数量" :styleType="$store.state.app.dialogType"></dialogHeader>
      <div class="filter-container filter-params">
        <component
          v-for="comp in tableComponents.filter(o => o.isMust === true)"
          :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
          :validrule="comp.validrule"
          :key="comp.compKey"
          :codeField="comp.codeField"
          :textField="comp.textField"
          :popupsKey="comp.compKey"
          :is="comp.component"
          :code="formField[comp.codeField]"
          :text="formField[comp.textField]"
          @changeCode="getComponentCode"
          @focusCode="getFocusCode"
          :disabled="comp.disabled"
          :isRequire="comp.isRequire"
          :span="comp.span || 8"
          :isMul="comp.isMul"
          :labelName="comp.labelName"
          :lookuptype="comp.lookuptype"
          :options="comp.options"
          :dateOptionsType="comp.dateOptionsType"
          :dataToObject="comp.dataToObject"
          :readonly="comp.readonly"
          :placeholder="comp.placeholder"
          :isInput="comp.isInput"
        ></component>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{comp.text}}</el-button>
      </div>
    </el-dialog>
    <print
      v-if="isPrintShow"
      :rowData="rowData"
      @detailPrintClose="detailPrintClose"
      :isPrintShow="isPrintShow"
      :formField="formField"
    />
  </section>
</template>
<script>
import { formMixins } from "@/components/wms/mixins/formMixins";
import request from "@/utils/request";
export default {
  // 组件混入对象
  mixins: [formMixins],
  components: {
    dialogHeader: () => import("@/components/dialogHeader"), //弹窗标题
    print: () => import("./print")
  },
  props: {
    isShow: { type: Boolean, default: false },
    rowData: { type: Object, default: {} }
  },
  data() {
    return {
      // 是否显示
      showDialog: this.isShow,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.print(),
          text: "箱号打印"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "edit_compKey1",
          labelName: "仓库",
          span: 23,
          codeField: "WAREHOUSE_ID",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          options: []
        },
        {
          compKey: "edit_compKey2",
          labelName: "打印数量",
          span: 23,
          codeField: "printNum",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
          changed: val => {
            if (!val) {
              return;
            }
            if (this.formField.printNum < 1) {
              this.$refs["edit_compKey2"][0].modelCode = 1;
              this.formField.printNum = 1;
            }
            this.$refs["edit_compKey2"][0].modelCode = (
              this.formField.printNum + ""
            ).replace(/[^\d]/g, "");
            this.formField.printNum = (this.formField.printNum + "").replace(
              /[^\d]/g,
              ""
            );
          }
        }
      ],
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        printNum: "",
        WAREHOUSE_ID: ""
      },
      // 控制打印弹窗
      isPrintShow: false
    };
  },
  created() {
    if (this.showDialog) {
      this.querySelect();
    }
  },
  methods: {
    close() {
      this.showDialog = false;
      this.$emit("detailClose");
    },
    //打印
    print() {
      if (!this.formField.WAREHOUSE_ID) {
        this.$message({
          message: "请选择仓库"
        });
        return;
      }
      if (!this.formField.printNum) {
        this.$message({
          message: "请输入打印数量"
        });
        return;
      }
      this.isPrintShow = true;
    },
    detailPrintClose() {
      this.isPrintShow = false;
    },
    querySelect() {
      request({
        url: "/mp/wm/vl/basedata/warehouseuser/queryUserByWHBox.do",
        method: "post",
        data: {
          IS_ENABLE: "1"
        }
      }).then(res => {
        res.listRow.map(item => {
          this.tableComponents[0].options.push({
            label: item.WAREHOUSE_NAME,
            value: item.WAREHOUSE_ID
          });
        });
      });
    }
  }
};
</script>
